/*
 * public class ChooseBillboardBean
 * author: adam barney
 * backing bean that takes care of login as well as choosing a billboard.
 */

/*
 * This file is part of WhatItDo.
 *
 * WhatItDo is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * WhatItDo is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with WhatItDo.  If not, see <http://www.gnu.org/licenses/>.
 */

package net.sourceforge.whatitdo.billboardWeb;

import java.util.ArrayList;
import java.util.Collection;
import net.sourceforge.whatitdo.billboard.model.Billboard;
import net.sourceforge.whatitdo.billboard.model.DataHelper;

import javax.faces.model.SelectItem;

public class ChooseBillboardBean {
    // private ArrayList<String> allNames = Billboard.getAllNames();
//    private ArrayList<String> allNames = Billboard.getAllNames();
    private String name = new String();
    /*
     * These properties are used by login.jsp
     */
    private String username;
    private String password;
    Billboard billboard = new Billboard();
    
    
    // PROPERTY: name - this is the billboard name
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
    // PROPERTY: username
    public String getUsername() {
        return username;
    }
    public void setUsername(String username) {
        this.username = username;
    }
    // PROPERTY: password
    public String getPassword() {
        return password;
    }
    public void setPassword(String password) {
        this.password = password;
    }
    public String validateLogin() {
	System.out.println("Validating login.");
	System.out.println("Username = " + this.username);
	System.out.println("Password = " + this.password);
	if (DataHelper.isValidLogin(this.username, this.password)) {
	    return "valid";
	} else {
	    return "invalid";
	}
	    
    }
    
    public Collection<SelectItem> getNameItems() {
	Collection<SelectItem> allNames = new ArrayList<SelectItem>();
	String billboardName = new String();
	ArrayList<String> names = new ArrayList<String>();
	names = DataHelper.getBillboardNamesForUser(username);
	if (names.size() != 0) {
	    for (int i = 0; i < names.size(); i++) {
		billboardName = names.get(i);
		allNames.add(new SelectItem(billboardName));
	    }
	} else {
	    System.out.println("Names is empty");
	}
	return allNames;
    }
    
    public String createBillboardAction() {
	System.out.println("Made it to createBillboardAction");
	String newId = String.valueOf((int)(1000000*Math.random()));
	billboard = new Billboard();
	billboard.createNew(newId, username);
	return "new";
    }
    
    
    
//    public Collection<SelectItem> getNameItems() {
//	return allNames;
//    }
//    
//    private static Collection<SelectItem> allNames;
//    static {
//	allNames = new ArrayList<SelectItem>();
//	String billboardName = new String();
//	ArrayList<String> names = new ArrayList<String>();
////	names = Billboard.getAllNames();
//	names = DataHelper.getBillboardsForUser(username);
//	if (names.size() != 0){
//	for (int i = 0; i < names.size(); i++) {
//	    billboardName = names.get(i);
//	    allNames.add(new SelectItem(billboardName));
//	}
//	} else {
//	    System.out.println("Names is empty");
//	}
//    }

}
